﻿using System;
using System.Collections.Generic;
using System.Text;

namespace TheCell
{
    public class Location
    {
        public int X
        { get; private set; }
        public int Y
        { get; private set; }
        public int Area
        { get; private set; }

        public Location(int x, int y)
        {
            this.X = x;
            this.Y = y;
            this.Area = this.GetArea(x, y);
        }

        private int GetArea(int x, int y)
        {
            int n1 = this.GetNumber(x);
            int n2 = this.GetNumber(y);
            return this.GetAreaByNumber(n1, n2);
        }

        private int GetNumber(int number)
        {
            int result = 3;
            if (Math.Abs(number - 5) < 2)
            {
                result = 2;
            }
            else if (number < 5)
            {
                result = 1;
            }

            return result;
        }

        private int GetAreaByNumber(int n1, int n2)
        {
            return (n1 - 1) * 3 + n2;
        }
    }
}
